package com.jan.client;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

import net.sf.json.JSONObject;

public class ReciveHandle
    implements Runnable
{
  private Socket socket;
  public ReciveHandle(Socket socket){
    this.socket=socket;
  }

  @Override
  public void run()
  {
    InputStream in;
    byte[] bs=new byte[1024];
    try
    {
      in = socket.getInputStream();
      while(true){
        if(in.available()>0){
          int length=in.read(bs);
          String s=new String(bs,0,length);
          JSONObject json=JSONObject.fromObject(s);
          DataPacket packet=new DataPacket(json.getString("sender"),json.getString("reciver"),json.getString("msg"));
          System.out.println(packet.getSender()+": "+packet.getMsg());
        }
      }
    }
    catch (IOException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   

  }

}
